import Vue from 'vue'
import VueRouter from 'vue-router'

// import Home from '../views/Home.vue'
// import Carousel from '@/views/Carousel.vue'
// import Pdfsdy from '@/views/Pdfsdy.vue'
// import Upload from '@/views/Upload.vue'
// import Webgl from '@/views/Webgl.vue'
// import Tree from '@/views/Tree.vue'
// import SpanAdd from '@/views/SpanAdd.vue'
// import Download from '@/views/Download.vue'
// import Slide from '@/views/Slide.vue'
// import Echart from '@/views/Echart.vue'
// import Charts from '@/views/Charts.vue'
// import Symbols from '@/views/Symbols.vue'
// import Canyon from '@/views/Canyon.vue'
// import Progress from '@/views/Progress.vue'
// import ProgressCopy from '@/views/ProgressCopy.vue'
// import Canvas from '@/views/Canvas.vue'
// import CaseOfficeManagement from '@/views/CaseOfficeManagement.vue'
// import CaseOfficeManagementCopy from '@/views/CaseOfficeManagementCopy.vue'
// import FunctionRoomStatistics from '@/views/FunctionRoomStatistics.vue'
// import LawEnforcementSupervision from '@/views/LawEnforcementSupervision.vue'
// import Gauge from '@/views/Gauge.vue'
// import axiosJson from '@/views/axiosJson.vue'
// import busLine from '@/views/busLine.vue'
// import render from '@/views/render.vue'
// import AlarmSmsTemplate_DialogAdd from '@/views/AlarmSmsTemplate_DialogAdd.vue'
// import Input from '@/views/Input.vue'
// import Drag from '@/views/Drag.vue'
// import timePicker from '@/views/timePicker.vue'


//  全局导入组件
const ZF_PAGES = [];
var real_PAGES = [];
const routes =[];

const requireComponent = require.context(
    //  其组件目录的相对路径
    '@/views/',
    //  是否查询其子目录
    true,
    //  匹配基础组件文件名的正则表达式, 这里可以匹配的文件名为TdXxxx.vue格式
    /.(vue)$/
);

console.log(requireComponent.keys());

requireComponent.keys().forEach(fileName => {
    //  获取组件的路径
    //  剥去文件名开头的 `'./` 和结尾的扩展名
    ZF_PAGES.push(fileName.replace(/^\.\/(.*)\.\w+$/, '$1'));
});

console.log(ZF_PAGES);

real_PAGES = ZF_PAGES.filter(e =>{
    return e.length < 10
})


//  驼峰转下划线
function humpToLine(name) {
    let _name = name.replace(name[0], name[0].toLowerCase());

    return _name.replace(/([A-Z])/g, '_$1').toLowerCase();
}


real_PAGES.map(page => {
    let pluginPage = page;
    let lineFileName = humpToLine(pluginPage);
    let _path = `/${lineFileName}`;
    routes.push({
        path: _path,
        name: page,
        component: resolve => require([`@/views/${page}.vue`], resolve),
        meta: {
            currentMenu: page
        }
    });
})


Vue.use(VueRouter)

//   const routes = [
//   {
//     path: '/',
//     name: 'Home',
//     component: Home
//   },
//   {
//     path: '/about',
//     name: 'About',
//     component: About
//   },
//   {
//     path: '/carousel',
//     name: 'Carousel',
//     component: Carousel
//   },
//   {
//     path: '/symbols',
//     name: 'Symbols',
//     component: Symbols
//   },
//   {
//     path: '/canyon',
//     name: 'Canyon',
//     component: Canyon
//   },
//   {
//     path: '/echart',
//     name: 'Echart',
//     component: Echart
//   },
//   {
//     path: '/charts',
//     name: 'Charts',
//     component: Charts
//   },
//   {
//     path: '/download',
//     name: 'Download',
//     component: Download
//   },
//   {
//     path: '/upload',
//     name: 'Upload',
//     component: Upload
//   },
//   {
//     path: '/webgl',
//     name: 'Webgl',
//     component: Webgl
//   },
//   {
//     path: '/tree',
//     name: 'Tree',
//     component: Tree
//   },
//   {
//     path: '/pdfsdy',
//     name: 'Pdfsdy',
//     component: Pdfsdy
//   },
//   {
//     path: '/slide',
//     name: 'Slide',
//     component: Slide
//   },
//   {
//     path: '/span_add',
//     name: 'SpanAdd',
//     component: SpanAdd
//   },
//   {
//     path: '/progress',
//     name: 'Progress',
//     component: Progress
//   },
//   {
//     path: '/progress_copy',
//     name: 'ProgressCopy',
//     component: ProgressCopy
//   },
//   {
//     path: '/Case_office_management',
//     name: 'CaseOfficeManagement',
//     component: CaseOfficeManagement
//   },
//   {
//     path: '/Case_office_management_copy',
//     name: 'CaseOfficeManagementCopy',
//     component: CaseOfficeManagementCopy
//   },
//   {
//     path: '/function_room_statistics',
//     name: 'FunctionRoomStatistics',
//     component: FunctionRoomStatistics
//   },
//   {
//     path: '/LawEnforcementSupervision',
//     name: 'LawEnforcementSupervision',
//     component: LawEnforcementSupervision
//   },
//   {
//     path: '/canvas',
//     name: 'Canvas',
//     component: Canvas
//   },
//   {
//     path: '/gauge',
//     name: 'Gauge',
//     component: Gauge
//   },
//   {
//     path: '/axiosJson',
//     name: 'axiosJson',
//     component: axiosJson
//   },
//   {
//     path: '/busLine',
//     name: 'busLine',
//     component: busLine
//   },
//   {
//     path: '/render',
//     name: 'render',
//     component: render
//   },
//   {
//     path: '/AlarmSmsTemplate_DialogAdd',
//     name: 'AlarmSmsTemplate_DialogAdd',
//     component: AlarmSmsTemplate_DialogAdd
//   },
//   {
//     path: '/input',
//     name: 'Input',
//     component: Input
//   },
//   {
//     path: '/drag',
//     name: 'Drag',
//     component: Drag
//   },
//   {
//     path: '/time_picker',
//     name: 'timePicker',
//     component: timePicker
//   },
// ]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
